package com.ld.front.controller.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ld.admin.service.system.SysTimedtaskService;
import com.ld.common.model.json.ApiResult;
import com.ld.common.model.json.ApiResultConverter;
import com.ld.front.controller.FrontBasicController;
import com.ld.shieldsb.common.core.model.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 定时任务服务
 * 
 * @ClassName TimedTaskController
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2018年12月26日 下午5:35:58
 *
 */
@Api(tags = "定时任务服务") // description 必填 文档显示 标题
@RestController
@RequestMapping("${shieldsb.frontPath}/timedtask")
public class TimedTaskController extends FrontBasicController<Object> {
    @Autowired
    protected SysTimedtaskService sysTimedtaskService;

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "获取执行的时间", notes = "传入cron表达式和获取次数n（默认5，最多20次）返回接下来n次的执行时间字符串") // value 必填文档显示
    @RequestMapping(value = "/getExcuteTime", method = { RequestMethod.GET }) // method 必填 否则文档会很冗余
    public ApiResult getExcuteTime(
            @ApiParam(name = "CronExpression", value = "cron表达式", required = true) @RequestParam("CronExpression") String cron,
            @ApiParam(name = "numTimes", value = "执行次数") @RequestParam(required = false) Integer numTimes) {
        numTimes = numTimes == null ? 5 : numTimes;
        Result result = sysTimedtaskService.getExcuteTime(cron, numTimes);
        String flag = "获取执行时间失败！";
        return ApiResultConverter.result2ApiResult(result, flag);
    }

}
